package com.movie.controller;

import com.movie.dto.MovieDTO;
import com.movie.service.MovieService;
import com.movie.utils.Result;  // ✅ 确认你项目里有这个工具类，没有的话我可以帮你写一个

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/movie")
public class MovieController {

    @Autowired
    private MovieService movieService;

    @GetMapping("/list")
    public Result<List<MovieDTO>> getAllMovies(@RequestHeader("X-User-Id") Integer userId) {
        return Result.success(movieService.getAllMovies(userId));
    }

    @GetMapping("/detail")
    public Result<MovieDTO> getMovieDetail(@RequestParam Integer id,
                                           @RequestHeader("X-User-Id") Integer userId) {
        return Result.success(movieService.getMovieDetail(id, userId));
    }

    @GetMapping("/search")
    public Result<List<MovieDTO>> searchMovies(@RequestParam String keyword) {
        return Result.success(movieService.searchMovies(keyword));
    }

    @GetMapping("/category")
    public Result<List<MovieDTO>> getMoviesByCategory(@RequestParam String category,
                                                      @RequestHeader("X-User-Id") Integer userId) {
        return Result.success(movieService.getMoviesByCategory(category, userId));
    }

    @GetMapping("/top")
    public Result<List<MovieDTO>> getTopRatedMovies(@RequestParam(defaultValue = "10") Integer limit) {
        return Result.success(movieService.getTopRatedMovies(limit));
    }

    // 推荐接口
    @GetMapping("/recommend")
    public Result<List<MovieDTO>> recommendMovies(@RequestHeader("X-User-Id") Integer userId) {
        return Result.success(movieService.recommendMovies(userId));
    }
}
